<%@ page import="pojoCla.NewsChnl" %>
<%@ page import="java.util.List" %>
<%@ page import="pojoCla.News" %>
<%@ page import="java.util.ArrayList" %><%--
  Created by IntelliJ IDEA.
  User: zhazha
  Date: 2021/9/1
  Time: 11:37
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title></title>
    <meta charset="utf-8">
    <link href="../css/main.css" rel="stylesheet">
    <%
        Object user = session.getAttribute("user");
        if(user == null){
            response.sendRedirect("../login.jsp");
            return;
        }
    %>
</head>
<body>
<!-- 新闻管理 -->
<div class="AccountManagement_c" id="NewsManagement_c">
    <h3>新闻管理
        <div class="amcl fr">
            <select class="fl NewsManagement_search" id="selNewsChnlName">
                <option>=请选择=</option>
                <%
                    List<NewsChnl> list = (List<NewsChnl>)session.getAttribute("newsChnlList");
                    if(list.size() > 0){
                        for(NewsChnl ns: list){
                        %>
                        <option><%=ns.getName() %></option>
                <%
                         }
                    }else{
                        %>
                <option></option>
                <%
                    }
                %>
            </select>
            <input type="text" placeholder="新闻关键字" class="fl" name="" id="selNews" value="${sessionScope.selNewsKeyword}">
            <div class="search fl" id="selNews_btn"><img src="../images/search.png"></div>
        </div>
    </h3>
    <!--功能按钮-->
    <div class="AM_ct text_center">
        <div class="AM_ct_in">
            <div class="add_btn df_btn fl" id="add_news_btn">发布</div>
            <div class="edit_btn df_btn fl" id="edit_news_btn">编辑</div>
            <div class="delete_btn df_btn fl" id="delete_news_btn">删除</div>
        </div>
    </div>
    <!--显示新闻-->
    <div class="list">
        <ul class="list_h">
            <li class="b20"><label><span>新闻标题</span></label></li>
            <li class="b20"><label>栏目名称</label></li>
            <li class="b20"><label>发布时间</label></li>
            <li class="b20"><label>操作</label></li>
        </ul>
        <div class="list_b_c">

                <%
                    List<News> newsPageList = (List<News>) session.getAttribute("newsPageList");
                    if(newsPageList.size() > 0){
                        List<News> notTop = new ArrayList<>();
                        for(News n: newsPageList){
                            if(n.getTop() == 1){
                        %>
                 <ul class="list_b">
                     <li class="b20"><label><input type="checkbox" name="news"><input type="hidden" id="<%=n.getId() %>"><input type="hidden" name="<%=n.getKeyword()%>"><span  style="color: red;text-decoration:underline;cursor: default;"><%="[已置顶]"%></span><span><%=n.getTitle() %></span></label></li>
                <li class="b20"><label name="chnlName"><%=n.getChnlName()%></label><input type="hidden" value="<%=n.getDetail()%>"></li>
                <li class="b20"><label><%=n.getCrtime()%></label></li>
                <li class="b20"><label style="color: #2980b6;text-decoration:underline;cursor: default;" name="newsTop"><%="[取消置顶]"%></label></li>
                 </ul>
                <%
                            }else{
                                notTop.add(n);
                            }
                        }
                        for(News t: notTop){
                            %>
                <ul class="list_b">
                <li class="b20"><label><input type="checkbox" name="news"><input type="hidden" id="<%=t.getId() %>"><input type="hidden" name="<%=t.getKeyword()%>"> <span  style="color: red;text-decoration:underline;cursor: default;"></span><span><%=t.getTitle() %></span></label></li>
                <li class="b20"><label name="chnlName"><%=t.getChnlName()%></label><input type="hidden" value="<%=t.getDetail()%>"></li>
                <li class="b20"><label><%=t.getCrtime()%></label></li>
                <li class="b20"><label style="color: red;text-decoration:underline;cursor: default;" name="newsTop"><%="[设置置顶]" %></label></li>
                </ul>
                <%
                        }
                    }else{
                %>
            <ul class="list_null">
                <li class="text_center">未找到新闻！</li>
            </ul>
                <%
                        }
                %>
        </div>

        <div class="pull_page" id="newsPage">
            <div class="fl pull_page_up" name="1">首页</div>
            <ul>
                <li name="${sessionScope.newsPageIndex - 1}">上一页</li>
                <li class="on">${sessionScope.newsPageIndex}</li>
                <li name="${sessionScope.newsPageIndex + 1}">下一页</li>
            </ul>
            <div class="fl pull_page_down" name="${sessionScope.newsSumPage}">末页</div>&nbsp;
            <span class="pull_page_down">总页数:${sessionScope.newsSumPage}</span>
        </div>

    </div>
</div>

<!--发布新闻-->
<div class="list dn" style="position: fixed;width: 100%;height: 100%;left: 0;top: 0;background-color: white" id="release_news">
    <ul class="list_h">
        <li class="b80"><label>发布新闻</label></li>
        <span class="fr add_Account_close"><img src="../images/close.png"></span>
    </ul>
    <div class="list_b_c" id="release_news_in">
        <div class="release_news">
            <div class="news_title">
                <label class="text_center">标题</label>
                <input type="text" placeholder="填写标题" name="newsCenter" id="addNewsCenter"><br>
                <span style="color: red" id="newsErrMSG"></span>
            </div>
            <div class="news_title" style="margin-top: 20px">
                <label class="text_center">关键字设置</label>
                <input type="text" placeholder="填写关键字" name="newsCenter" id="addNewsKeyword">
            </div>
            <div class="column_name">
                <label class="text_center">栏目</label>
                <select class="column_name_release" id="addNewsSelectID">
                    <option>==请选择==</option>
                    <% if(list.size() > 0){
                        for(NewsChnl ns: list){
                    %>
                    <option><%=ns.getName() %></option>
                    <%
                        }
                    }else{
                    %>
                    <option></option>
                    <%
                        }
                    %>
                </select>
            </div>
            <div class="column_name">
                <label class="text_center">是否置顶</label>
                <select class="column_name_release" id="addNewsSelectTop">
                    <option>否</option>
                    <option>是</option>
                </select>
            </div>
            <textarea class="release_news_content" id="addNewsText" rows="50" cols="60" placeholder="编辑正文"></textarea>
            <div class="release_news_ok_btn text_center" id="addNewsButton">发<i>我</i>布</div>
            <span style="color: red"></span>
        </div>


    </div>
</div>

<!--删除新闻-->
<div class="add_Account dn"  id="delete_news">
    <div class="add_Account_c">
        <div class="add_Account_h">
            <div class="add_Account_h_in">
                删除新闻
                <span class="fr add_Account_close"><img src="../images/close.png"></span>
            </div>
        </div>
        <div style="width: 280px;margin:25px auto;color: red;">确定删除选中的新闻吗？</div>
        <div class="add_Account_ok_btn text_center" id="delete_news_ok_btn">确<i>皮</i>定</div>
    </div>
</div>
<!--编辑新闻-->
<div class="list dn" style="position: fixed;width: 100%;height: 100%;left: 0;top: 0;background-color: white" id="edit_news">
    <ul class="list_h">
        <li class="b80"><label>编辑新闻</label></li>
        <span class="fr add_Account_close"><img src="../images/close.png"></span>
    </ul>
    <div class="list_b_c" id="edit_news_in">
        <div class="release_news">
            <div class="news_title">
                <label class="text_center">标题</label>
                <input type="text" placeholder="填写标题" name="editNewsKeyword" id="editNewsCenter"><br>
                <span style="color: red" id="editNewsErrMSG"></span>
            </div>
            <div class="news_title" style="margin-top: 20px">
                <label class="text_center">关键字设置</label>
                <input type="text" placeholder="填写关键字" name="editNewsKeyword" id="editNewsKeyword">
            </div>
            <div class="column_name">
                <label class="text_center">栏目</label>
                <select class="column_name_release" id="editNewsSelectID">
                    <option>==请选择==</option>
                    <% if(list.size() > 0){
                        for(NewsChnl ns: list){
                    %>
                    <option><%=ns.getName() %></option>
                    <%
                        }
                    }else{
                    %>
                    <option></option>
                    <%
                        }
                    %>
                </select>
            </div>
            <div class="column_name">
                <label class="text_center">是否置顶</label>
                <select class="column_name_release" id="editNewsSelectTop">
                    <option>否</option>
                    <option>是</option>
                </select>
            </div>
            <textarea class="release_news_content" id="editNewsText" rows="50" cols="60" placeholder="编辑正文"></textarea>
            <div class="release_news_ok_btn text_center" id="editNewsButton">修<i>我</i>改</div>
            <span style="color: red"></span>
        </div>


    </div>
</div>
<!--设置置顶-->
<div class="add_Account dn"  id="top_news">
    <div class="add_Account_c">
        <div class="add_Account_h">
            <div class="add_Account_h_in">
                置顶新闻
                <span class="fr add_Account_close"><img src="../images/close.png"></span>
            </div>
        </div>
        <div style="width: 280px;margin:25px auto;color: red;">确定置顶这个新闻吗？</div>
        <div class="add_Account_ok_btn text_center" id="top_news_ok_btn">确<i>皮</i>定</div>
    </div>
</div>

</body>
<script type="text/javascript" src="../js/jquery.js"></script>
<script type="text/javascript" src="../js/main.js"></script>
<script type="text/javascript">
    var selChnlName = "${sessionScope.selNewsChnlName}";
    var addNewsMSG ="${sessionScope.addNewsMSG}";
    var editNewsMSG ="${sessionScope.editNewsMSG}";
    var delNewsMSG = "${sessionScope.delNewsMSG}";
    if(selChnlName != ""){
        $('#selNewsChnlName').val(selChnlName);
    }
    if(addNewsMSG != ""){
        alert(addNewsMSG);
    }else if(editNewsMSG != ""){
        alert(editNewsMSG);
    }else if(delNewsMSG != ""){
        alert(delNewsMSG);
    }
    <%
    session.removeAttribute("addNewsMSG");
    session.removeAttribute("editNewsMSG");
    session.removeAttribute("delNewsMSG");
    %>
</script>
</html>
